<%@ page import="com.wmm.bean.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Date" %>
<%@ page import="com.wmm.service.StudentService" %>
<%@ page import="com.wmm.bean.PageBean" %>
<%@ page import="com.wmm.bean.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<html>
<head>
    <script src="js/bootstrap.min.js"></script>
    <meta charset="utf-8">
    <title>简易学生管理</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
        function check() {
            var flag = confirm("确定删除这条记录吗？");

            if (flag) {
                return true;

            } else {
                return false;
            }
        }

        function fun1() {
            var numbers = $("#number11").val();
            var name11 = $("#name11").val();
            $("#a1").attr("href", "queryStudent?bystunumber=" + numbers + "&byname=" + name11);
        }

        function deleteAll() {

            if (isSelected()) {
                if (confirm("确定删除选中的数据吗？")) {
                    var params = [];
                    var del = document.getElementsByTagName("input");
                    for (var i = 0; i < del.length; i++) {
                        if (del[i].name != "delAll") {
                            if (del[i].checked) {
                                del[i].name = "check";
                                params[params.length++] = del[i].value;
                            }
                        }
                    }
                    window.location = "deleteAll?params=" + params;
                }
            } else {
                alert("请至少选择一条要删除的数据！")
            }

        }

        //判断是否有数据被选中
        function isSelected() {
            var isFlag = false;
            var del = document.getElementsByTagName("input");
            for (var i = 0; i < del.length; i++) {
                if (del[i].name == "delAll") {

                    isFlag = false;
                } else {
                    if (del[i].checked) {
                        isFlag = true;
                    }
                }
            }
            return isFlag;
        }

        //点击最上面的按钮实现下方选择框的反向勾选
        function delFun() {

            var del = document.getElementsByTagName("input");
            for (var i = 0; i < del.length; i++) {
                if (del[i].name != "delAll") {
                    del[i].checked = !del[i].checked;
                }
            }


        }


        function selectPage() {
            var numbers = $("#number11").val();
            var name11 = $("#name11").val();
            var href = $(this).getAttribute("href");
            alert(href);
        }
    </script>
<body style="background-color: lightskyblue">

<div style="border: 1px solid red;height: 120px;font-size: 30px;align-items: center;">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
    <a href="add.jsp" target="_self">增加学生</a>
<%--    <a href="${pageContext.request.contextPath}/findAllStudentByPage" target="_self">展示全部的学生信息</a>--%>


    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" placeholder="按照学号查询" name="bystunumber" id="number11"
           style="font-size:25px;background-color: lightgray;width:180px;">
    <input type="text" placeholder="按照姓名查询" name="byname" id="name11"
           style="background-color: lightgray;font-size:25px;width:220px;">
    <a href="queryStudent" target="_self" onclick="fun1()" id="a1">查询</a>

</div>
<br/>
<br/>
<br/>

<%--<div align="right"><a href="#" onclick="return deleteAll()">删除选中的学生</a></div>--%>


<table width="100%" border="3px solid green" cellspacing="0px" cellpadding="0px" class="table table-hover table-striped">
    <caption style="text-align: center; font-size: larger;" >学生信息显示</caption>
    <tr>
        <th><input type="button" id="delAll" name="delAll" onclick="delFun()" value="反选"/></th>
        <th>学号</th>
        <th>学生姓名</th>
        <th>性别</th>
        <th>出生日期</th>
        <th>邮箱</th>
        <th>备注信息</th>
        <th>操作</th>
    </tr>

    <%

        StudentService studentService = new StudentService();
        PageBean<Student> pageBean = ((PageBean<Student>)session.getAttribute("queryList"));
        List<Student> list = (List<Student>) pageBean.getList();
        request.setAttribute("pageBean",pageBean);
        for (Student student : list) {
            request.setAttribute("student", student);
    %>

    <tr>
        <td><input type="checkbox" id=<%=student.getId()%>  value=<%=student.getId()%> /></td>
        <td><%=student.getId() %>
        </td>
        <td><%=student.getName()%>
        </td>
        <td><%=student.getSex() %>
        </td>
        <td><%=student.getBirthday()%>
        </td>
        <td><%=student.getMailbox()%>
        </td>
        <td><%=student.getMemo()%>
        </td>
        <td><a href="updateStudent?studentno=<%=student.getId()%>&method=show">修改</a> &nbsp;&nbsp;
            <a href="deleteStudent?studentno=<%=student.getId()%>" onclick="return check()">删除</a>
        </td>
    </tr>



    <%
            }
    %>
</table>

<br/>
<div align="center">

    <p style="color: cornflowerblue;">一共有  <%=pageBean.getTotalCount()%> 条记录，每页分成了 <%=pageBean.getRows()%>条记录,
        当前第 <%=pageBean.getCurrentPage()%> 页,一共有<%=pageBean.getTotalPage()%>页</p>
    <ul class="pagination" style="align-content: center">
        <li><a href="#">&laquo;</a></li>
        <%
        for(int i = 1;i <= pageBean.getTotalPage();i++) {

            if(i == pageBean.getCurrentPage()){


            %>
        <li style="background-color: darkgrey;"><a href="findStudentByPage?currentPage=<%=i%>&rows=5" onclick="selectPage()"><%=i%></a></li>

        <%
                }
            else {
          %>
        <li><a href="findStudentByPage?currentPage=<%=i%>&rows=5" onclick="selectPage()"><%=i%></a></li>


        <%
                }
        }
    %>
        <li><a href="#">&raquo;</a></li>
    </ul>
</div>

</body>
</html>
